package baidu;

import java.util.Scanner;

//输入时钟中显示的字符，转换为数字显示
public class Clock {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int testCase;
		char[][] star;
		String[] strings = new String[7];
		testCase = scanner.nextInt();
		int firstIndex, lastIndex;
		int first = 0, second = 0, third = 0, forth = 0;
		StringBuilder builder = new StringBuilder();
		for (int j = 1; j <= testCase; j++) {
			builder = new StringBuilder();
			builder.append("Case# " + j + "result " );
			for (int i = 0; i < strings.length; i++) {
				strings[i] = scanner.nextLine();
			}
			// 获取有效区域
			firstIndex = strings[0].indexOf("*");
			lastIndex = strings[0].indexOf("*");

			star = new char[7][lastIndex - firstIndex + 1];
			for (int i = 0; i < strings.length; i++) {
				star[i] = strings[i].toCharArray();
			}
			for (int k = 0; k < 6; k++) {
				first = getNumber(star, 0, 5);
			}
			for (int k = 0; k < 6; k++) {
				second = getNumber(star, 7, 12);
			}
			for (int k = 0; k < 6; k++) {
				third = getNumber(star, 16, 21);
			}
			for (int k = 0; k < 6; k++) {
				forth = getNumber(star, 23, 29);
			}
            if (first == 0) {
				builder.append("");
			}else {
				builder.append(first);
			}
            builder.append(second + ":");
            if (third == 0) {
				builder.append("");
			}else {
				builder.append(third);
			}
            builder.append(forth);
            System.out.println(builder.toString());
		}
		scanner.close();
	}

	public static int getNumber(char[][] star, int first, int end) {
		if(star[0][first] != '*'){
			return 1;
		}
		//处理4‘ 7
		if(star[6][first] != '*'){
			if(star[3][first] == '*'){
				return 4;
			}else {
				return 7;
			}
		}
		//处理2和3
		if(star[1][first] != '*'){
			if(star[4][first] == '*'){
				return 2;
			}else {
				return 3;
			}
		}
		//处理5 . 6
		if(star[1][end] != '*'){
			if(star[4][first] == '*'){
				return 6;
			}else {
				return 5;
			}
		}
		//处理9
		if(star[5][first] != '*'){
			return 9;
		}
		//处理0.8
		if(star[3][first + 1] != '*'){
			return 0;
		}
		else {
			return 8;
		}
	}
}
